import 'package:flutter/material.dart';
import 'package:badges/badges.dart';
import 'package:flutter_dwh5/utils/api.dart';

class My extends StatefulWidget {
  @override
  State<My> createState() => _MyState();
}

class _MyState extends State<My> {
  @override
  void initState() {
    super.initState();
    getData();
  }

  getData() async {
    var res = await Api.LoginAPI();
    print(res);
  }

  int loginState = 1;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('我的'),
        elevation: 0,
      ),
      body: ListView(
        children: [
          Column(
            children: [
              Container(
                alignment: Alignment.center,
                padding: EdgeInsets.all(15),
                color: Color.fromRGBO(213, 21, 25, 1),
                child: Row(
                  children: [
                    Container(
                      child: CircleAvatar(
                        backgroundImage: AssetImage('images/login/logo.png'),
                      ),
                      width: 62,
                      height: 62,
                    ),
                    if (loginState == 0)
                      Container(
                        margin: EdgeInsets.only(left: 15, right: 15),
                        child: Text(
                          '您好！请登录',
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 16.0,
                              fontWeight: FontWeight.bold),
                        ),
                      ),
                    if (loginState == 1)
                      GestureDetector(
                        onTap: () {
                          Navigator.pushNamed(context, 'edit');
                        },
                        child: Row(
                          children: [
                            Container(
                              child: Text(
                                '用户名',
                                style: TextStyle(
                                    color: Colors.white, fontSize: 16),
                              ),
                              margin: EdgeInsets.only(right: 5, left: 15),
                            ),
                            Container(
                              child: Image.asset(
                                'images/my/edit.png',
                                width: 15,
                                height: 15,
                              ),
                            )
                          ],
                        ),
                      ),
                    if (loginState == 0)
                      ElevatedButton(
                          onPressed: () {
                            Navigator.pushNamed(context, 'login');
                          },
                          // style: ElevatedButton.styleFrom(
                          //     backgroundColor: Colors.white),
                          child: Text(
                            '登录/注册',
                            style: TextStyle(color: Colors.black, fontSize: 16),
                          ))
                  ],
                ),
              ),
              //订单
              Container(
                padding: EdgeInsets.all(15),
                alignment: Alignment.center,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      child: Text(
                        '我的订单',
                        style: TextStyle(
                            fontSize: 16, fontWeight: FontWeight.bold),
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                        Navigator.pushNamed(context, 'order');
                      },
                      child: Row(
                        children: [
                          Container(
                            child: Text('全部订单'),
                          ),
                          Icon(Icons.chevron_right_rounded)
                        ],
                      ),
                    )
                  ],
                ),
              ),
              Divider(
                height: 0.5,
                color: Color.fromRGBO(225, 225, 225, 1),
              ),
              Container(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Column(
                      children: [
                        Container(
                            child: Badge(
                          badgeContent: Text(
                            '3',
                            style: TextStyle(color: Colors.white),
                          ),
                          child: Image.asset(
                            'images/my/1.png',
                            width: 27,
                            height: 24,
                            fit: BoxFit.cover,
                          ),
                        )),
                        Container(
                          margin: EdgeInsets.only(top: 10),
                          child: Text('待付款'),
                        ),
                      ],
                    ),
                    Column(
                      children: [
                        Container(
                            child: Badge(
                          badgeContent: Text(
                            '3',
                            style: TextStyle(color: Colors.white),
                          ),
                          child: Image.asset(
                            'images/my/2.png',
                            width: 27,
                            height: 24,
                            fit: BoxFit.cover,
                          ),
                        )),
                        Container(
                          margin: EdgeInsets.only(top: 10),
                          child: Text('待发货'),
                        ),
                      ],
                    ),
                    Column(
                      children: [
                        Container(
                            child: Badge(
                          badgeContent: Text(
                            '3',
                            style: TextStyle(color: Colors.white),
                          ),
                          child: Image.asset(
                            'images/my/3.png',
                            width: 27,
                            height: 24,
                            fit: BoxFit.cover,
                          ),
                        )),
                        Container(
                          margin: EdgeInsets.only(top: 10),
                          child: Text('待收货'),
                        ),
                      ],
                    ),
                    GestureDetector(
                      onTap: () {
                        Navigator.pushNamed(context, 'evaluate');
                      },
                      child: Column(
                        children: [
                          Container(
                              child: Badge(
                            badgeContent: Text(
                              '3',
                              style: TextStyle(color: Colors.white),
                            ),
                            child: Image.asset(
                              'images/my/4.png',
                              width: 27,
                              height: 24,
                              fit: BoxFit.cover,
                            ),
                          )),
                          Container(
                            margin: EdgeInsets.only(top: 10),
                            child: Text('待评价'),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                padding: EdgeInsets.all(15),
              ),
              Container(
                padding: EdgeInsets.all(15),
                color: Color.fromRGBO(249, 249, 249, 1),
                width: MediaQuery.of(context).size.width,
                height: 120,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      child: Center(
                        child: Image.asset('images/my/image1.png',
                            width: MediaQuery.of(context).size.width * 0.43,
                            height: 94),
                      ),
                    ),
                    Container(
                      child: Center(
                        child: Image.asset('images/my/image2.png',
                            width: MediaQuery.of(context).size.width * 0.43,
                            height: 94),
                      ),
                    )
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.all(15),
                height: 50,
                width: MediaQuery.of(context).size.width,
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: Color.fromRGBO(225, 225, 225, 1),
                            width: 0.5))),
                child: GestureDetector(
                  onTap: () {
                    Navigator.pushNamed(context, 'address');
                  },
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Container(
                            child: Image.asset(
                              'images/my/address.png',
                              width: 15,
                              height: 15,
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.only(left: 5),
                            child: Text('收货地址'),
                          )
                        ],
                      ),
                      Container(
                        child: Icon(
                          Icons.chevron_right_rounded,
                          size: 20,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              Container(
                padding: EdgeInsets.all(15),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: Color.fromRGBO(225, 225, 225, 1),
                            width: 0.5))),
                height: 50,
                width: MediaQuery.of(context).size.width,
                child: GestureDetector(
                  onTap: () {
                    Navigator.pushNamed(context, 'proposal');
                  },
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Container(
                            child: Image.asset(
                              'images/my/complaint.png',
                              width: 15,
                              height: 15,
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.only(left: 5),
                            child: Text('投诉建议'),
                          )
                        ],
                      ),
                      Container(
                        child: Icon(
                          Icons.chevron_right_rounded,
                          size: 20,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              Container(
                padding: EdgeInsets.all(15),
                color: Colors.white,
                height: 50,
                width: MediaQuery.of(context).size.width,
                child: GestureDetector(
                  onTap: () {
                    Navigator.pushNamed(context, 'setting');
                  },
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Container(
                            child: Image.asset(
                              'images/my/setting.png',
                              width: 15,
                              height: 15,
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.only(left: 5),
                            child: Text('设置'),
                          )
                        ],
                      ),
                      Container(
                        child: Icon(
                          Icons.chevron_right_rounded,
                          size: 20,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
